package com.yanqu.road.server.cmd.activity.jieshi;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.JieShiProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.jieshi.JieShiModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_JIESHI_HANDLER_EVENT, desc = "处理事件")
public class JieShiHandlerEventCmd extends AbstractCommand {


    private int eventId;

    private int position;

    private String param = "";

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        JieShiProto.JieShiHandlerEventReqMsg reqMsg = JieShiProto.JieShiHandlerEventReqMsg.parseFrom(packet.getBytes());
        eventId = reqMsg.getEventId();
        position = reqMsg.getPosition();
        param = reqMsg.getParam();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(JieShiModule.class).handlerEvent(position, eventId, param);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            JieShiProto.JieShiHandlerEventRespMsg.Builder respMsg = JieShiProto.JieShiHandlerEventRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_JIESHI_HANDLER_EVENT, respMsg);
        }
    }
}
